package com.snicesoft.jfinal.vue.source;

import com.jfinal.kit.HttpKit;
import com.jfinal.template.source.ISource;

import java.io.File;

public class HttpSource implements ISource {
    private String url;

    public HttpSource(String url) {
        this.url = url;
    }

    @Override
    public boolean isModified() {
        return true;
    }

    @Override
    public String getCacheKey() {
        return null;
    }

    @Override
    public StringBuilder getContent() {
        return new StringBuilder(HttpKit.get(this.url));
    }

    @Override
    public String getEncoding() {
        return null;
    }

    private String buildFinalFileName(String baseTemplatePath, String fileName) {
        if (baseTemplatePath == null) {
            return fileName;
        } else {
            char firstChar = fileName.charAt(0);
            String finalFileName;
            if (firstChar != '/' && firstChar != '\\') {
                finalFileName = baseTemplatePath + File.separator + fileName;
            } else {
                finalFileName = baseTemplatePath + fileName;
            }

            return finalFileName;
        }
    }
}
